#!/bin/bash

function ipv4_addr() {
    local dev="$1"
    local addr=$( ip addr show dev "${dev}" |sed -n '/inet /{ s/inet \([0-9\.]*\).*$/\1/p }' )
    echo ${addr}
}

function link_dev_none_or_die() {
    local dev="$1"
    local r=$( ip link show ${dev} 2> /dev/null )
    if [ -n "${r}" ]
    then
        echo "${dev} already exists, delete it first please."
        exit 2
    fi
    return 0
}
